let query = (location.search).substring(1)
let arr = decodeURI(query)
console.log(arr);
let arr1 = arr.split('&')
console.log(arr1);
// let item = arr1.split("=")[1]
let aObj = arr1[2].split('=')[1]
console.log(aObj);

// let OOa = document.querySelector(".ooa")
let Oa = document.querySelector(".oa")
Oa.innerText = `${aObj}`

// productid
let item = arr1[1].split('=')[1]
console.log(item);




const xhr = new XMLHttpRequest();
xhr.open("get",`http://chst.vip:1234/api/getproduct?productid=${item}`);
xhr.send(null);

xhr.onreadystatechange = function(){
    let omain = document.querySelector("main");
    if(xhr.readyState === 4){
        if(xhr.status === 200){
            let res = JSON.parse(xhr.responseText);
            console.log(res)

            // let regExp = /(?<=imgurl=)[^'"]*/;
            let ele = "";
            res.result.forEach(item => {
                // console.log(item);
                var img = item.productImg;
                // console.log(img);
                ele += `<div>
                            ${img}
                            <p>${item.productName}</p>
                        </div>
                        <div>
                            <a href="">${item.bjShop}</a>
                        </div>
                        <span>网友评价</span>`
                
                // `<li>
                //             <a href="./bijiaxq.html?categoryid=${item.categoryId}&productid=${item.productId}&brandname=${item.brandName}">
                //                 ${img}
                //                 <div>
                //                     <h4>${item.productName}</h4>
                //                     <span>${item.productPrice}</span>
                //                     <br>
                //                     <p>${item.productQuote}</p>
                //                     <i>${item.productCom}</i>
                //                 </div>
                //             </a>
                //         </li>`
                
                
                // `<li>
                //             <h4>${item.productName}</h4>
                //             <span>${item.productFrom} | ${item.productTime}</span>
                //             <i>${item.productTips}</i>
                //             <img src="${img}" alt="">
                //             <p>${item.productInfo2}</p>
                //         </li>`
                
            });
            omain.innerHTML = ele;
        }
    }
};






const xhr1 = new XMLHttpRequest();
xhr1.open("get",`http://chst.vip:1234/api/getproductcom?productid=${item}`);
xhr1.send(null);

xhr1.onreadystatechange = function(){
    let oul = document.querySelector("ul");
    console.log(oul);
    if(xhr1.readyState === 4){
        if(xhr1.status === 200){
            let res1 = JSON.parse(xhr1.responseText);
            console.log(res1)

            // let regExp = /(?<=imgurl=)[^'"]*/;
            let ele = "";
            res1.result.forEach(item => {
                // console.log(item);
                // var img = item.productImg;
                // console.log(img);
                ele += `<li>
                            <h4>
                                <span>${item.comName}</span>
                                <span>${item.comTime}</span>
                            </h4>
                            <p>${item.comContent}</p>
                            <i>${item.comFrom}</i>
                        </li>`
            });
            oul.innerHTML = ele;
        }
    }
}